import BasicLayout from '@/core/components/layouts/BasicLayout'
import IsAuth from '@/lib/auth/components/IsAuth'
import FinishCheckoutComponent from '@/lib/checkout/components/FinishCheckout'
import { useRouter } from 'next/router'
import axios from 'axios'

export async function getServerSideProps(context) {
  const { order_id } = context.query
  await axios.post(
    `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/finish-checkout?orderName=${order_id}`,
    {},
    { headers: context.req.headers }
  )
  return { props: {} }
}

export default function Finish() {
  const router = useRouter()

  return (
    <IsAuth>
      <BasicLayout>
        <FinishCheckoutComponent query={router.query || {}} />
      </BasicLayout>
    </IsAuth>
  )
}
